package life.majiang.community.mapper;

import life.majiang.community.dto.CommentLikeCountDTO;
import life.majiang.community.model.CommentLikeCount;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;

import java.util.List;

public interface LikeCountMapper {
    @Insert("INSERT INTO LIKE_COMMENT(user_id, comment_id, question_id) VALUES(#{userId}, #{id}, #{questionId})")
    boolean insertLikeCount(CommentLikeCountDTO commentLikeCountDTO);

    @Delete("DELETE FROM LIKE_COMMENT WHERE user_id = #{userId} AND comment_id = #{id} AND question_id = #{questionId}")
    boolean removeLikeCount(CommentLikeCountDTO commentLikeCountDTO);

    @Select("SELECT id,user_id,comment_id,question_id FROM LIKE_COMMENT WHERE user_id = #{param1} AND question_id = #{param2}")
    List<CommentLikeCount> getCommentLikeCountDTOListByUserIdAndQuestionId(Long userId, Long questionId);


//    根据问题id删除点赞，管理员删除帖子，自动删除点赞列表
    @Delete("DELETE FROM LIKE_COMMENT WHERE question_id = #{questionId}")
    boolean removeLikeCountByQuestionId(Long questionId);

//    根据评论id删除点赞，管理员删除一级评论时，自动删除点赞列表
    @Delete("DELETE FROM LIKE_COMMENT WHERE comment_id = #{commentId}")
    boolean removeLikeCountByCommentId(Long commentId);
}
